using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;

namespace AstroX
{
    class CameraControl
    {
        OutputPort campower = new OutputPort(AstoXPinMap.CamPowerPin, false);
        OutputPort camsig = new OutputPort(AstoXPinMap.CamRecord, false);
        Timer t;
        public  CameraControl()
        {
            FlightControl.FlightPhaseChanged += new FlightPhaseChangeHandler(FlightControl_FlightPhaseChanged);
            
        }

        void FlightControl_FlightPhaseChanged(FlightPhases newphase)
        {
            if (newphase == FlightPhases.Ascent)
            {
                Thread thread = new Thread(() =>
                {
                    Thread.Sleep(1000);
                    campower.Write(true);

                    Thread.Sleep(10 * 1000);
                    camsig.Write(true);
                    Thread.Sleep(1000);
                    camsig.Write(false);
                });
                thread.Start();
            }
            else if (newphase == FlightPhases.Shutdown)
            {
                Thread thread = new Thread(() =>
                {
                    camsig.Write(true);
                    Thread.Sleep(1000);
                    camsig.Write(false);

                    campower.Write(false);
                    Thread.Sleep(1000);
                    campower.Write(true);

                });
                thread.Start();
            }
            
        }

    }
}
